//
//  XALoginAlertView.m
//  xappSmartParkiOS
//
//  Created by yangxiaohui on 2018/4/11.
//  Copyright © 2018年 Alibaba. All rights reserved.
//

#import "XALoginAlertView.h"

//#import "UserInfoShared.h"
@interface XALoginAlertView()
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UIButton *registerBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *confirmCenterLayout;

@end

@implementation XALoginAlertView

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setupUI];
    
}

- (void)setupUI{

    self.backView.layer.cornerRadius = 5;
    self.registerBtn.layer.cornerRadius = 5;
    self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    
//    UITapGestureRecognizer *removeGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeSelf)];
//    [self addGestureRecognizer:removeGesture];
    [self shakeToShow:self.backView];
}
///确认按钮
- (IBAction)registerClick:(id)sender {
    if (self.backBlock) {
        self.backBlock(YES);
    }
    [self removeSelf];
    
}
//取消按钮
- (IBAction)cancelClick:(id)sender {
    if (self.backBlock) {
        self.backBlock(NO);
    }
    [self removeSelf];
}

/**
 是否显示取消按钮

 @param isShow 是否展示
 */
- (void)showCancleBtn:(BOOL)isShow{
    if (self.confirmCenterLayout) {
        self.confirmCenterLayout.constant=isShow?65.0:0.0;
        self.cancelBtn.hidden=isShow?NO:YES;
    }
}
//确认按钮
- (IBAction)confirmAction:(id)sender {
    
    if (self.backBlock) {
        self.backBlock(YES);
    }
    [self removeSelf];
    
}

- (void)showAlertViewCallBack:(ButtonActionBlock)callback
{
    _backBlock=callback;
    
}

- (void)removeSelf{

    if (!self.isAutoDisapper) {
        [self removeFromSuperview];
    }
    
    
}
- (IBAction)checkLocationBtnAction:(id)sender {
    [self removeSelf];
    if(self.CheckLocationBlock){
        self.CheckLocationBlock();
    }
}
- (IBAction)appointmentBtnAction:(id)sender {
    [self removeSelf];
    if(self.AppointmentBlock){
        self.AppointmentBlock();
    }
}

#pragma mark - 弹性震颤动画
- (void)shakeToShow:(UIView *)aView
{
    CAKeyframeAnimation * popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    popAnimation.duration = 0.35;
    popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.05f, 1.05f, 1.0f)],
                            //                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DIdentity]];
    popAnimation.keyTimes = @[@0.0f, @0.5f, /*@0.75f,*/ @0.8f];
    popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                     //                                    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [aView.layer addAnimation:popAnimation forKey:nil];
}


@end
